package com.woniuxy.main.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import com.woniuxy.main.pojo.Shared;

public interface SharedMapper {

	//全部动态 - 教练
	@Select("select shid,s.uid,createDate,content,nickName name from shared s inner join coach c on s.uid=c.uid "
			+ "inner join user u on c.uid=u.uid where publicLevel in(0,1)")
	public List<Shared> allSharedCoach();
	//全部动态 - 学员
	@Select("select shid,s.uid,createDate,content,nickName name from shared s inner join student t on s.uid=t.uid "
			+ "inner join user u on s.uid=u.uid where publicLevel in(0,1)")
	public List<Shared> allSharedStudent();
	
	
	//我的关注 - 教练 -- 指定用户id
	@Select("select shid,s.uid,createDate,content,nickName name from shared s inner join coach c on s.uid=c.uid "
			+ "inner join user u on c.uid=u.uid "
			+ "where c.uid in(select uid from user where uid in (select targetUid from follow where uid = #{uid})) "
			+ "and publicLevel in(0,1)")
	public List<Shared> allFollowedCoach(Shared shared);
	//我的关注 - 学员 -- 指定用户id
	@Select("select shid,s.uid,createDate,content,nickName name from shared s inner join student t on s.uid=t.uid "
			+ "inner join user u on s.uid=u.uid "
			+ "where t.uid in(select uid from user where uid in (select targetUid from follow where uid = #{uid})) "
			+ "and publicLevel in(0,1)")
	public List<Shared> allFollowedStudent(Shared shared);
	
	
	//相互关注 - 教练 -- 指定用户id
	@Select("select shid,s.uid,createDate,content,nickName name from shared s inner join coach c on s.uid=c.uid "
			+ "inner join user u on c.uid=u.uid "
			+ "where c.uid in(select uid from user where uid in (select uid from follow "
			+ "where targetUid = #{uid} and uid in (select targetUid from follow where uid = #{uid}))) "
			+ "and publicLevel in(0,1)")
	public List<Shared> allFriendCoach(Shared shared);
	//相互关注 - 学员 -- 指定用户id
	@Select("select shid,s.uid,createDate,content,nickName name from shared s inner join student t on s.uid=t.uid "
			+ "inner join user u on s.uid=u.uid "
			+ "where t.uid in(select uid from user where uid in (select uid from follow "
			+ "where targetUid = #{uid} and uid in (select targetUid from follow where uid = #{uid}))) "
			+ "and publicLevel in(0,1)")
	public List<Shared> allFriendStudent(Shared shared);
	
	
	//自己可见 - 教练/学员 -- 指定用户id
	@Select("select shid,s.uid,createDate,content,nickName name from shared s inner join user u on s.uid=u.uid where s.uid = #{uid}")
	public List<Shared> allCurrentUser(Shared shared);
	
	//发布动态
	@Insert("insert into shared value(default,#{uid},#{content},#{createDate})")
	public int insertShared(Shared shared);
	
	//删除动态
	@Delete("delete from shared where shid=#{shid}")
	public int deleteThis(Shared shared);
}
